package ${package.Controller};

import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bee.beemanage.utils.result.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import static com.bee.beemanage.utils.result.ResultTool.success;

@RestController
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@Api(value ="${table.comment}",tags = "${table.comment}")
public class ${table.controllerName} {

    @Resource
    private ${table.serviceName} ${table.serviceName?uncap_first};

    /**
    * 新增${table.comment}
    * @param ${entity?uncap_first}
    * @return
    */
    @ApiOperation(value = "新增${table.comment}", notes = "新增${table.comment}")
    @PostMapping
    public Result save(@RequestBody ${entity} ${entity?uncap_first}) {
        ${entity?uncap_first}.setCreateTime(LocalDateTime.now());
        return success(${table.serviceName?uncap_first}.save(${entity?uncap_first}));
    }
    /**
    * 修改${table.comment}
    * @param ${entity?uncap_first}
    * @return
    */
    @ApiOperation(value = "修改${table.comment}", notes = "修改${table.comment}")
    @PostMapping("/edit")
    public Result edit(@RequestBody ${entity} ${entity?uncap_first}) {
        ${entity?uncap_first}.setUpdateTime(LocalDateTime.now());
        return success(${table.serviceName?uncap_first}.updateById(${entity?uncap_first}));
    }
    /**
    * 根据id删除${table.comment}
    * @param id
    * @return
    */
    @ApiOperation(value = "通过id删除${table.comment}", notes = "通过id删除${table.comment}")
    @DeleteMapping("/{id}")
    public Result removeById(@PathVariable String id) {
        return success(${table.serviceName?uncap_first}.removeById(id));
    }
    /**
    * 根据id批量删除${table.comment}
    * @param ids
    * @return
    */
    @ApiOperation(value = "通过id批量删除${table.comment}", notes = "通过id批量删除${table.comment}")
    @PostMapping("/batch")
    public Result removeByIds(@RequestBody String[] ids) {
    List<String> idsList = Arrays.asList(ids);
        return success(${table.serviceName?uncap_first}.removeByIds(idsList));
    }
    /**
    * ${table.comment}分页查询
    * @param page
    * @param ${entity?uncap_first}
    * @return
    */
    @ApiOperation(value = "${table.comment}分页查询", notes = "${table.comment}分页查询")
    @GetMapping("/page")
    public Result page(Page<${entity}> page, ${entity} ${entity?uncap_first}) {
        return success(${table.serviceName?uncap_first}.page(page, Wrappers.query(${entity?uncap_first})));
    }

    /**
    * 根据id查询${table.comment}
    * @param id
    * @return
    */
    @ApiOperation(value = "通过id查询${table.comment}", notes = "通过id查询${table.comment}")
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") String id) {
        return success(${table.serviceName?uncap_first}.getById(id));
    }
}